class ShopCategory < ApplicationRecord
  mount_uploader :avatar, BaseUploader

  has_many :spus
  has_many :option_types

  validates :name, presence: { message: "名字不能为空" }

  belongs_to :parent, class_name: 'ShopCategory', foreign_key: 'parent_id', optional: true
  has_many :children, class_name: 'ShopCategory', foreign_key: 'parent_id'

  has_many :shop_category_brands, dependent: :destroy
  has_many :brands, through: :shop_category_brands
  has_many :coupons
  has_many :active_shop_categories, dependent: :destroy
  has_many :actives, through: :active_shop_categories
end
